﻿using System;
using System.Security.Principal;

namespace OnlineFamilyCalendar.Common.Security
{
    public class OnlineFamilyCalendarPrincipal : IPrincipal
    {
        private IIdentity _identity;
        private string _role;

        /// <summary>
        /// Initializes a new instance of the GenericPrincipal class 
        /// from an Identity and a List of role names 
        /// to which the user represented by that Identity belongs
        /// </summary>
        /// <param name="identity"></param>
        /// <param name="roles"></param>
        public OnlineFamilyCalendarPrincipal(IIdentity identity, string role)
		{
            _identity = identity;
            _role = role;
		}

        /// <summary>
        /// Determines whether the current Principal belongs to the specified role.
        /// </summary>
        /// <param name="role">The name of the role for which to check membership</param>
        /// <returns>true if the current CustomPrincipal is a member of the specified role; 
        /// otherwise, false.</returns>
        public bool IsInRole(string role)
        {
            return String.Compare(_role, role, true) == 0;
        }

        /// <summary>
        /// Gets the Identity of the user represented by the current Principal.
        /// </summary>
        public IIdentity Identity
        {
            get { return _identity; }
            set { _identity = value; }
        }
    }
}
